package com.hongdee.crm.task.service.impl;

import com.hongdee.annotation.MethodComment;
import com.hongdee.common.util.DateUtils;
import com.hongdee.common.util.StringUtil;
import com.hongdee.crm.Constant;
import com.hongdee.crm.task.dao.IBcMaintainTypeTaskDao;
import com.hongdee.crm.task.dao.ITCrmCarMaintainTaskDao;
import com.hongdee.crm.task.dao.ITCrmTaskDao;
import com.hongdee.crm.task.dto.MainTainDTO;
import com.hongdee.crm.task.entity.TCrmTask;
import com.hongdee.crm.task.service.ITCrmCarMaintainTaskService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import java.text.DecimalFormat;
import java.util.*;

import static com.hongdee.crm.Constant.DEF_MILE;

/**
 * 名  称: TCrmCarTwoMaintainTaskServiceImpl
 * 类  型: class
 * 描  述: 车辆保养二保任务相关
 * 路  径: com.hongdee.crm.task.service.impl
 * 作  者: wangshuai
 * 日  期: 2017/3/4 16:20
 */
@Component("TwoCarMaintainTaskService")
public class TCrmCarTwoMaintainTaskServiceImpl implements ITCrmCarMaintainTaskService {

    @Autowired
    private ITCrmCarMaintainTaskDao carMaintainTaskDao;

    @Autowired
    private ITCrmTaskDao taskDao;

    @Autowired
    private IBcMaintainTypeTaskDao bcMaintainTypeTaskDao;

    private final String BY_CODE="by";
    private final String YYYYMMDD="yyyy-MM-dd";
    private final int LIMIT = 1000;
    private final String MAINTAINNAME="二保";

    private final String EB="eb";
    private final String MBY="mby";
    private final String TXTS="txts";
    private final String JSYF="jsyf";
    private final String MBR="mbr";

    private MainTainDTO mbyMainTainDTO;
    private MainTainDTO mbrMainTainDTO;

    /**
     * 车辆二保
     * sql查询规则：
     * 1、查询工单表，查询出所有的与首保有关的工单；
     * 2、车辆与首保工单连接，此处查询出的皆是有过首保的车辆
     * 3、查询工单表，查询出所有不与首保有关的工单，此处则包含二保、常规保养；
     * 4、将首保的车辆信息 与 非首保的工单进行排除，余下的皆是有过首保，但是没有其它保养的车辆信息
     * 5、执行查询；
     * 计算步骤：
     * 1、根据t_bc_param_set查询出设置首保类型的公司
     * 2、根据公司ID取出配置的首保相关信息
     * 3、查询出公司所配置的首保关系的维修项目
     * 4、根据sql查询出相应的车辆信息
     * 5、遍历车辆信息
     *  1）、计算从质保开始至首次保养结算时间中间的天数
     *  2）、计算每天车辆的平均里程
     *  3）、根据每天的平均里程 计算出车辆5000公里所需要的时间
     *  4）、根据计算的时间，获得从结算日开始相加的月份，是否与结算日+6个月的时间
     *  5）、判断理论二保日(首保结算日+（5000/平均里程）=理论二保日)，与结算二保目标月(首保结算日)进行比较
     *  6）、首先判断理论二保日是否小于结算二保目标月，如果小于则执行首理论二保日
     *  7）、如果大于则执行二保目标月
     *  8）、判断执行的目标月（目标日）时间是否在下月1号至下下月1号零点之间
     *  9）、判断任务是否已经存在，如存在则跳出循环，如不存在则生成TCrmTask实体保存
     * @throws Exception
     */
//    @Scheduled(cron="0 30 2 28 * ? *") //每月28日2点30执行
    @Override
    @MethodComment(name = "二保 二保月定时任务")
    public Integer carMaintainQuartz() throws Exception {
        Integer nums=0;
        List<Map<String,Object>> companyList=carMaintainTaskDao.findCompanyList(EB+"_"+MBY,EB+"_"+MBR);
        //遍历公司信息
        for(Map<String,Object> map:companyList){
            //取得公司ID
            String compnayId=String.valueOf(map.get("company_id"));
            //根据公司ID 判断是否有首保任务 首保月任务
            int num=this.carMaintain(compnayId,"","");
            nums+=num;
        }
        return nums;
    }

    @Override
    public Integer carMaintain(String companyId,String startTime,String endTime) throws Exception {
        //获得当前时间的时间戳
        long nowTime=MaintainUtil.getNowTime();
        this.getMainTainParamInfo(companyId);
        long maintainTime=DateUtils.addMonthLongTime(nowTime,-12);
        int nums=0;
        nums+=findCarTwoMaintain(companyId,nowTime,maintainTime,startTime,endTime,mbrMainTainDTO.getCode());
        nums+=findCarTwoMaintain(companyId,nowTime,maintainTime,startTime,endTime,mbyMainTainDTO.getCode());
        return  nums;
    }

    /**
     * 查询符合条件的二保车辆信息
     * @param companyId
     * @param nowTime
     * @param maintainTime
     * @throws Exception
     */
    private Integer findCarTwoMaintain(String companyId,long nowTime,long maintainTime,String startTime,String endTime,String code)throws Exception{
        Integer nums=0;
        int start = 0;
        List<Map<String,Object>> maintainTypeList=bcMaintainTypeTaskDao.findSetMaintainType(companyId,EB);
        if(maintainTypeList!=null){
            while(true) {
                //生成sql相关
                StringBuffer sqlStr=new StringBuffer();
                List<Object> paramLists=new ArrayList<>();
                this.analyCompalyToSql(companyId,sqlStr, paramLists,code);
                paramLists.add(companyId);
                paramLists.add(maintainTime);
                paramLists.add(companyId);
                paramLists.add(start*LIMIT);
                paramLists.add(LIMIT);
                List<Map<String,Object>> lists=carMaintainTaskDao.carMaintainList(sqlStr.toString(),paramLists);
                //退出判断
                if(lists == null){
                    start=0;
                    break;
                }else {
                    List<TCrmTask> tasks=this.analyCars(lists,companyId,nowTime,startTime,endTime,code);
                    if(tasks.size()>0){
                        nums+=tasks.size();
                        long start1 = System.currentTimeMillis();
                        carMaintainTaskDao.insertMaintailLists(tasks);
                        long end = System.currentTimeMillis();
                        System.out.println("运行时间：" + (end - start1) + "毫秒");//应该是end - start
                    }
                }
                start++;
            }
        }
        return nums;
    }

    /**
     * 解析查询出的车辆信息，并计算生成关于车辆的二保任务信息
     * @param lists
     * @param companyId
     * @param nowTime
     * @return
     * @throws Exception
     */
    private List<TCrmTask> analyCars(List<Map<String,Object>> lists,String companyId,long nowTime,String startTime,String endTime,String code) throws Exception {
        List<TCrmTask> list=new ArrayList<>();
        for(Map<String,Object> map:lists){
            String plateNum="";
            if(map.get("plate_num")==null){
                String vin=String.valueOf(map.get("vin"));
                plateNum=vin.substring(vin.length()-6,vin.length());
                map.put("plate_num",plateNum);
            }
            //车辆ID
            String carId=String.valueOf(map.get("car_id"));
            //质保开始时间
            Long guaranteeDate=null;
            if(map.get("guarantee_start_date")!=null){
                guaranteeDate=Long.valueOf(String.valueOf(map.get("guarantee_start_date")));
            }else{
                guaranteeDate=Long.valueOf(String.valueOf(map.get("buy_date")));
            }
            //车辆行驶里程
            Float runMile=this.getRunMaile(map);
            //车牌号
            //进厂时间
            long enterDaate=Long.valueOf(String.valueOf(map.get("maintain_time")));
            if(enterDaate<=guaranteeDate){
                continue;
            }
            //1、计算从质保开始至首次保养结算时间中间的天数
            Integer days=DateUtils.dateDifference(enterDaate,guaranteeDate);
            //2、计算每天车辆的平均里程
            Float avgMails=runMile/days;
            //3、根据每天的平均里程 计算出车辆5000公里所需要的时间
            Float mailDays=DEF_MILE/avgMails;
            Float mailHour=mailDays*24;
            System.out.println(DateUtils.addHourLongTime(enterDaate,+mailHour.intValue()));
            //向上取整取出天数
            //理论上的二保日,首保进厂时间+根据5000公里计算的天数
            long maintainTimeL=Long.valueOf(String.valueOf(map.get("next_maintain_time")));
            //4、根据计算的时间，获得从结算日开始相加的月份，是否与结算日+6个月的时
            long sixTwoMaintainTime=DateUtils.addMonthLongTime(enterDaate,+mbyMainTainDTO.getJsyfNums().intValue());
            //5、判断理论二保日，与结算二保日进行比较

            switch (code){
                case "eb_mbr":
                    this.saveTaskMbr(maintainTimeL,sixTwoMaintainTime,nowTime,startTime,endTime,map,enterDaate,list,companyId);
                    break;
                case "eb_mby":
                    this.saveTaskMby(maintainTimeL,sixTwoMaintainTime,nowTime,startTime,endTime,map,enterDaate,list,companyId);
                    break;
            }
//
//
//            List<Map<String,Object>> taskMapList=this.towMaintainTime(sixTwoMaintainTime,maintainTimeL,nowTime);
//            for (Map<String,Object> taskMap:taskMapList) {
//                long taskTime=Long.parseLong(String.valueOf(taskMap.get("taskTime")));
//                long byTime=Long.parseLong(String.valueOf(taskMap.get("byTime")));
//                boolean ebflag=Boolean.parseBoolean(String.valueOf(taskMap.get("eb")));
//                //判断日期是否在下月之中也就是下月1号至下下月1号，如当前月3月，那么日期需要在4.1至5.1之间
//                boolean flag = DateUtils.checkTime(byTime,nowTime);
//                if(!"".equals(startTime) && !"".equals(endTime)){
//                    flag=DateUtils.checkTime(byTime,startTime,endTime);
//                }
//                if (flag) {
//                    //保存任务之前需要判断
//                    if (ebflag) {
//                        //二保目标日
//                        //根据车辆 查看首保日任务是否存在
//                        boolean taskFlag=this.checkSbTask(companyId,carId,mbrMainTainDTO.getCode(),byTime);
//                        if(taskFlag){//已经存在，则直接跳出循环
//                            System.out.println("二保日任务已经存在");
//                            continue;
//                        }
//                    } else {
//                        //二保目标月任务 无需查询是否存在首保日任务
//                        boolean taskFlag=this.checkSbTask(companyId,carId,mbyMainTainDTO.getCode(),byTime);
//                        if(taskFlag){//已经存在，则直接跳出循环
//                            System.out.println("二保月任务已经存在");
//                            continue;
//                        }
//                    }
//                    TCrmTask task = this.saveTask(map, taskTime, byTime, ebflag, enterDaate);
//                    list.add(task);
//                }
//            }
        }
        return list;

    }


    /**
     * 生成二保任务
     * @param maintainTimeL
     * @param sixTwoMaintainTime
     * @param nowTime
     * @param startTime
     * @param endTime
     * @param map
     * @param enterDaate
     * @param list
     * @param companyId
     * @throws Exception
     */
    private void saveTaskMbr(Long maintainTimeL,Long sixTwoMaintainTime,Long nowTime,String startTime,String endTime,
                             Map<String,Object> map,long enterDaate,List<TCrmTask> list,String companyId) throws Exception {
        if(maintainTimeL<sixTwoMaintainTime) {
            if(mbrMainTainDTO.getJsyfNums()!=null) {
                Map<String, Object> mbrMap = new HashMap<>();
                mbrMap.put("byTime", DateUtils.addDayLongTime(maintainTimeL, -mbrMainTainDTO.getTxtsNums().intValue()));
                mbrMap.put("taskTime", maintainTimeL);

                long taskTime = Long.parseLong(String.valueOf(mbrMap.get("taskTime")));
                long byTime = Long.parseLong(String.valueOf(mbrMap.get("byTime")));

                boolean flag = DateUtils.checkTime(byTime, nowTime);
                if (!"".equals(startTime) && !"".equals(endTime)) {
                    flag = DateUtils.checkTime(byTime, startTime, endTime);
                }
                //车辆ID
                String carId = String.valueOf(map.get("car_id"));
                String vin=String.valueOf(map.get("vin"));
                if (flag) {
                    //根据车辆 查看首保日任务是否存在
                    boolean taskFlag = taskDao.checkTaskByVinAndId(companyId, StringUtil.formatEmpty(map.get("vin")), carId,
                            mbyMainTainDTO.getCode(),BY_CODE, DateUtils.formatLongTimeByYYYYMMDD(byTime));
                    if (!taskFlag) {//已经存在，则直接跳出循环
                        String tpl = "%s车，车主[%s],二次保养提醒%s，上次保养时间%s.";
                        TCrmTask task = this.saveTask(map, taskTime, byTime, tpl, enterDaate, mbrMainTainDTO.getCode());
                        list.add(task);
                    }
                }
            }
        }
    }

    /**
     * 生成保存二保目标月任务
     * @param maintainTimeL
     * @param sixTwoMaintainTime
     * @param nowTime
     * @param startTime
     * @param endTime
     * @param map
     * @param enterDaate
     * @param list
     * @param companyId
     * @throws Exception
     */
    private void saveTaskMby(Long maintainTimeL,Long sixTwoMaintainTime,Long nowTime,String startTime,String endTime,
                             Map<String,Object> map,long enterDaate,List<TCrmTask> list,String companyId) throws Exception {
        //判断根据平均里程数算出来的是否大于六个月日期
        if(maintainTimeL>=sixTwoMaintainTime) {
            this.saveTaskMbyByTime(maintainTimeL,sixTwoMaintainTime,nowTime,startTime,endTime,map,enterDaate,list,companyId);
        }
        if(maintainTimeL<nowTime){
            this.saveTaskMbyByTime(maintainTimeL,sixTwoMaintainTime,nowTime,startTime,endTime,map,enterDaate,list,companyId);
        }
        if(maintainTimeL>nowTime && maintainTimeL<sixTwoMaintainTime){
            this.saveTaskMbyByTime(maintainTimeL,sixTwoMaintainTime,nowTime,startTime,endTime,map,enterDaate,list,companyId);
        }
    }

    private void saveTaskMbyByTime(Long maintainTimeL,Long sixTwoMaintainTime,Long nowTime,String startTime,String endTime,
                                   Map<String,Object> map,long enterDaate,List<TCrmTask> list,String companyId) throws Exception {
        if(mbyMainTainDTO.getJsyfNums()!=null) {
            Map<String, Object> mbyMap = new HashMap<>();
            mbyMap.put("byTime", DateUtils.addDayLongTime(sixTwoMaintainTime, -mbyMainTainDTO.getTxtsNums().intValue()));
            mbyMap.put("taskTime", sixTwoMaintainTime);

            long taskTime = Long.parseLong(String.valueOf(mbyMap.get("taskTime")));
            long byTime = Long.parseLong(String.valueOf(mbyMap.get("byTime")));
            //判断日期是否在下月之中也就是下月1号至下下月1号，如当前月3月，那么日期需要在4.1至5.1之间
            boolean flag = DateUtils.checkTime(byTime, nowTime);
            if (!"".equals(startTime) && !"".equals(endTime)) {
                flag = DateUtils.checkTime(byTime, startTime, endTime);
            }
            //车辆ID
            String carId = String.valueOf(map.get("car_id"));
            String vin = String.valueOf(map.get("vin"));
            if (flag) {
                boolean taskFlag = taskDao.checkTaskByVinAndId(companyId, StringUtil.formatEmpty(map.get("vin")), carId,
                        mbyMainTainDTO.getCode(),BY_CODE, DateUtils.formatLongTimeByYYYYMMDD(byTime));
//                boolean taskFlag = this.checkSbTask(companyId, vin, mbyMainTainDTO.getCode(), byTime);
                if (!taskFlag) {//已经存在，则直接跳出循环
                    String tpl = "%s车，车主[%s],二次保养提醒%s，上次保养时间%s.[目标月]";
                    TCrmTask task = this.saveTask(map, taskTime, byTime, tpl, enterDaate, mbyMainTainDTO.getCode());
                    list.add(task);
                }
            }
        }
    }


    /**
     * 生成二保类任务
     * @param mTmp
     * @param taskTime
     * @throws Exception
     */
    private TCrmTask saveTask(Map<String,Object> mTmp, long taskTime, long byTime, String tpl,long enterDate,String code) throws Exception {
        TCrmTask task = new TCrmTask();
        task.setCreateTime(new Date().getTime());
        task.setVIN(mTmp.get("vin").toString());
        task.setCarId(mTmp.get("car_id").toString());
        task.setPlateNum(mTmp.get("plate_num").toString());
        task.setCompanyId(mTmp.get("company_id").toString());
        task.setLinkman(com.hongdee.common.util.StringUtil.formatNull(mTmp.get("owner_name")));
        if(mTmp.get("owner_tel")!=null) {
            task.setLinkphone(mTmp.get("owner_tel").toString());
        }else{
            if(mTmp.get("owner_phone")!=null) {
                task.setLinkphone(mTmp.get("owner_phone").toString());
            }
        }
//        task.setSaId(mTmp.get("said")+"");
        task.setExpectDate(DateUtils.formatLongTime(byTime,YYYYMMDD));
        task.setStatus("0");
        task.setIsBack("0");
        task.setTypePCode(BY_CODE);

        String contentStr=new String();
        String byTimeStr=DateUtils.formatLongTime(byTime,YYYYMMDD);
        String taskTimeStr=DateUtils.formatLongTime(taskTime,YYYYMMDD);
        String enterDateStr= DateUtils.formatLongTime(enterDate,YYYYMMDD);
        task.setTypeCode(code);
        contentStr=String.format(tpl,task.getPlateNum(),task.getLinkman(),taskTimeStr,enterDateStr);
//                task.getPlateNum()+"车，车主["+task.getLinkman()+"],二次保养提醒"+taskTimeStr+"，上次保养时间"+enterDateStr+".[目标月]";
        task.setContent(contentStr);
        return task;
    }


//    /**
//     * 生成二保类任务
//     * @param mTmp
//     * @param taskTime
//     * @throws Exception
//     */
//    private TCrmTask saveTask(Map<String,Object> mTmp, long taskTime, long byTime, boolean ebflag,long enterDate) throws Exception {
//        TCrmTask task = new TCrmTask();
//        task.setVIN(mTmp.get("vin").toString());
//        task.setCarId(mTmp.get("car_id").toString());
//        task.setPlateNum(mTmp.get("plate_num").toString());
//        task.setCompanyId(mTmp.get("company_id").toString());
//        task.setLinkman(mTmp.get("contact_name").toString());
//        if(mTmp.get("contact_phone")!=null) {
//            task.setLinkphone(mTmp.get("contact_phone").toString());
//        }
////        task.setSaId(mTmp.get("said")+"");
//        task.setExpectDate(DateUtils.formatLongTime(byTime,YYYYMMDD));
//        task.setStatus("0");
//        task.setTypePCode(BY_CODE);
//
//        String contentStr=new String();
//        String byTimeStr=DateUtils.formatLongTime(byTime,YYYYMMDD);
//        String taskTimeStr=DateUtils.formatLongTime(taskTime,YYYYMMDD);
//        String enterDateStr= DateUtils.formatLongTime(enterDate,YYYYMMDD);
//        if(ebflag){
//            //首保日
//            task.setTypeCode(mbrMainTainDTO.getCode());
//            contentStr=task.getPlateNum()+"车，车主["+task.getLinkman()+"],二次保养提醒"+taskTimeStr+"，上次保养时间"+enterDateStr+".";
//        }else{
//            //首保月
//            task.setTypeCode(mbyMainTainDTO.getCode());
//            contentStr=task.getPlateNum()+"车，车主["+task.getLinkman()+"],二次保养提醒"+taskTimeStr+"，上次保养时间"+enterDateStr+".[目标月]";
//        }
//        task.setContent(contentStr);
//        return task;
//    }
//
//    /**
//     * 计算 并生成二保时间
//     * @param sixTwoMaintainTime
//     * @param maintainTimeL
//     * @return
//     * @throws Exception
//     */
//    private List<Map<String,Object>> towMaintainTime(long sixTwoMaintainTime,long maintainTimeL,long nowTime) throws Exception{
//        List<Map<String,Object>> list=new ArrayList<>();
//        if(maintainTimeL>=sixTwoMaintainTime) {
//            Map<String,Object> mbyMap=new HashMap<>();
//            mbyMap.put("eb", false);
//            mbyMap.put("byTime", DateUtils.addDayLongTime(sixTwoMaintainTime, -mbyMainTainDTO.getTxtsNums().intValue()));
//            mbyMap.put("taskTime", sixTwoMaintainTime);
//            list.add(mbyMap);
//        }else {
////            Long byTimeMbr=DateUtils.addDayLongTime(maintainTimeL, -mbrMainTainDTO.getTxtsNums().intValue());
////            if(byTimeMbr>=nowTime){
//            Map<String, Object> mbrMap = new HashMap<>();
//            mbrMap.put("eb", true);
//            mbrMap.put("byTime", DateUtils.addDayLongTime(maintainTimeL, -mbrMainTainDTO.getTxtsNums().intValue()));
//            mbrMap.put("taskTime", maintainTimeL);
//            list.add(mbrMap);
////            }else{
//            Map<String,Object> mbyMap=new HashMap<>();
//            mbyMap.put("eb", false);
//            mbyMap.put("byTime", DateUtils.addDayLongTime(sixTwoMaintainTime, -mbyMainTainDTO.getTxtsNums().intValue()));
//            mbyMap.put("taskTime", sixTwoMaintainTime);
//            list.add(mbyMap);
////            }
//
//        }
//        return list;
//    }



    private Float getRunMaile(Map<String,Object> map){
        if(map.get("maintain_mile")!=null){
            Float fRunMaile=Float.valueOf(String.valueOf(map.get("maintain_mile")));
            return fRunMaile;
        }
        return new Integer(DEF_MILE).floatValue();
    }

    /**
     * 检测任务是否已经存在，如果已经存在返回true，未存在返回false
     * @param companyId
     * @param vin
     * @param code
     * @return
     * @throws Exception
     */
    private boolean checkSbTask(String companyId,String vin,String code,long expectDate) throws Exception {
        String expectDateStr=DateUtils.formatLongTime(expectDate,YYYYMMDD);
        List<Map<String,Object>> lists=taskDao.findTasksByVin(companyId,vin,BY_CODE,code,expectDateStr);
        if(lists!=null){
            if(lists.size()>0){
                return true;
            }
        }
        return false;
    }

    /**
     * 根据公司所设定的维修项目 生成sql
     * @param companyId
     * @param sqlStr
     * @param paramLists
     */
    private void analyCompalyToSql(String companyId,StringBuffer sqlStr,List<Object> paramLists,String code){
        sqlStr.append("select temp1.*,car.guarantee_start_date,car.buy_date,car.owner_name,car.owner_tel,car.owner_phone from  (SELECT * FROM t_crm_car_maintain t1 " +
                "WHERE maintian_type = '首保' and company_id=? and maintain_time >?   " +
//                "and car_id not in (select car_id from t_crm_car_maintain where maintian_type='二保')" +
                "AND NOT EXISTS (select * from t_crm_car_maintain where t1.vin=vin and t1.company_id=company_id and maintian_type in ('二保','定保')) " +
                " )temp1 " +
                "LEFT JOIN t_crm_car car ON temp1.vin=car.vin and temp1.company_id=car.company_id " +
                "where car.company_id=? and (car.guarantee_start_date is not null or car.buy_date is not null)");
        Constant.REMIND_CLOSE_SQL(sqlStr,EB,code,"car");
//        sqlStr.append("not EXISTS(select * from t_crm_car_remindclose where car.id=user_carid and car.company_id=company_id and car.vin=vin) ");

        sqlStr.append("GROUP BY car.id " +
                "limit ?,? ");

    }

    private void analyMainType(StringBuffer sqlStr,List<Map<String,Object>> maintainTypeList,List<Object> paramLists){
        sqlStr.append(" ( ");
        for(int i=0;i<maintainTypeList.size();i++){
            Map<String,Object> map=maintainTypeList.get(i);
            String projectName=String.valueOf(map.get("maint_project_name"));
            sqlStr.append("item_name = ? ");
            paramLists.add(projectName);
            if(i<(maintainTypeList.size()-1)){
                sqlStr.append(" or ");
            }
        }
        sqlStr.append(" ) ");
    }


    /**
     * 解析参数信息 生成相应的DTO类
     * @param companyId
     * @throws Exception
     */
    private void getMainTainParamInfo(String companyId)throws Exception{
        //遍历
//        for (Map<String,Object> map:params) {
//            String mapCode=String.valueOf(map.get("code"));
//            if((EB+"_"+MBY).equals(mapCode)){
        //根据code值 查询其下属信息
        List<Map<String,Object>> mbyList=carMaintainTaskDao.findCompanyParamList(companyId,EB+"_"+MBY);
        if(mbyList!=null) {
            mbyMainTainDTO = MainTainDTO.analyParams(mbyList, EB + "_" + MBY + "_" + TXTS, EB + "_" + MBY + "_" + JSYF, EB + "_" + MBY);
            mbyMainTainDTO.setCode(EB + "_" + MBY);
            this.setMbyMainTainDTO(mbyMainTainDTO);
        }
//            }else if((EB+"_"+MBR).equals(mapCode)){
        List<Map<String,Object>> mbrList=carMaintainTaskDao.findCompanyParamList(companyId,EB+"_"+MBR);
        if(mbrList!=null) {
            mbrMainTainDTO = MainTainDTO.analyParams(mbrList, EB + "_" + MBR + "_" + TXTS, EB + "_" + MBR + "_" + JSYF, EB + "_" + MBR);
            mbrMainTainDTO.setCode(EB + "_" + MBR);
            this.setMbrMainTainDTO(mbrMainTainDTO);
        }
//            }
//        }
    }

    public MainTainDTO getMbyMainTainDTO() {
        return mbyMainTainDTO;
    }

    public void setMbyMainTainDTO(MainTainDTO mbyMainTainDTO) {
        this.mbyMainTainDTO = mbyMainTainDTO;
    }

    public MainTainDTO getMbrMainTainDTO() {
        return mbrMainTainDTO;
    }

    public void setMbrMainTainDTO(MainTainDTO mbrMainTainDTO) {
        this.mbrMainTainDTO = mbrMainTainDTO;
    }

    public static void main(String[] args) {
        try {
            long l1=DateUtils.addMonthLongTime(1490889600000L,+1);
            System.out.println(l1);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
